EasyCoding.uz

Home / Python / File Handling

File Handling & IO

Mark Complete

Read and write files safely using with.

Read a File

with open("notes.txt", "r") as f:
    text = f.read()
    print(text)

Write a File

with open("notes.txt", "w") as f:
    f.write("Hello file!")
Key takeaway: with closes the file automatically.

Ready to try it yourself?

Write a file and read it back.

← Functions Error Handling →